package org.scirp.ijmis.service.personpaper.impl;

import java.util.List;

import org.scirp.ijmis.dao.personpaper.ISendEmailLogDAO;
import org.scirp.ijmis.po.personpaper.SendEmailLog;
import org.scirp.ijmis.service.personpaper.ISendEmailLogService;
import org.test.mail.SendMail;

public class SendEmailLogServiceImpl implements ISendEmailLogService {
	private ISendEmailLogDAO sendEmailLogDAO;

	public List<SendEmailLog> selectAllByPaperId(Long paperId) {
		return sendEmailLogDAO.selectAllByPaperId(paperId);
	}

	public List<SendEmailLog> selectAllByPaperIdAndTypeId(Long paperId, Long emailTypeId) {
		return sendEmailLogDAO.selectAllByPaperIdAndTypeId(paperId, emailTypeId);
	}

	public boolean saveSendEmailLog(SendEmailLog sendEmailLog, String smtp, String sendFrom, String sendTo, String smtpName, String smtpPassword, String content, String subject) throws Exception {
		SendMail mail = new SendMail();
		Long pid = 0L;

		if (mail.sendMail(smtp, sendFrom, sendTo, smtpName, smtpPassword, content, subject)) {
			pid = sendEmailLogDAO.saveSendEmailLog(sendEmailLog);
			if (pid > 0) {
				return true;
			}
		}
		return false;
	}
	public Long saveSendEmailLog(SendEmailLog sendEmailLog){
		return sendEmailLogDAO.saveSendEmailLog(sendEmailLog);
	}
	public List<SendEmailLog> selectAllByToEmail(String toEmail) {
		return sendEmailLogDAO.selectAllByToEmail(toEmail);
	}

	public ISendEmailLogDAO getSendEmailLogDAO() {
		return sendEmailLogDAO;
	}

	public void setSendEmailLogDAO(ISendEmailLogDAO sendEmailLogDAO) {
		this.sendEmailLogDAO = sendEmailLogDAO;
	}

}
